<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
  </head>
  <body>
    <div id="app">
      <p>{{msg}}</p>
      <button v-on:click="clickHandler">btn</button>
    </div>
    <script>
      var app = new Vue({
        el: "#app",
        data: {
          msg: "hello world",
        },
        methods: {
          clickHandler: function () {
            // console.log(123);
            // 访问 msg  this就是app的一个引用
            // console.log(app.msg, this == app);
            // console.log(this.msg);
            this.msg = this.msg.split("").reverse().join("");
          },
        },
      });

      // 所有的 DOM 操作都由 Vue 来处理，你编写的代码只需要关注逻辑层面即可
    </script>

    <hr />
    <div id="app1">
      <button v-on:click="toggleSeen">toggle</button>
      <div
        v-if="seen"
        style="width: 100px; height: 100px; background-color: red"
      >
        box
      </div>
    </div>
    <script>
      new Vue({
        el: "#app1",
        data: {
          seen: true,
        },
        methods: {
          toggleSeen: function () {
            this.seen = !this.seen;
          },
        },
      });
    </script>
    <!-- vue 是由数据驱动 jq dom编程 -->

    <!-- 双向绑定 两种含义 表单 vue原理 -->
    <hr />

    <div id="app2">
      <input type="text" v-bind:value="value" v-on:input="inputHandler" />
      <p>{{value}}</p>
    </div>

    <script>
      new Vue({
        el: "#app2",
        data: {
          value: "123",
        },
        methods: {
          inputHandler: function (event) {
            // console.log(event.target.value);
            this.value = event.target.value;
          },
        },
      });
    </script>

    <hr />
    <div id="app3">
      <input type="text" v-model="value" />
      <p>{{value}}</p>
    </div>
    <script>
      new Vue({
        el: "#app3",
        data: {
          value: "000",
        },
      });
    </script>


<!-- 
Vue 构造函数

new Vue({
  el: 
  data:
  methods:
})


{{}}
v-bind
v-if
v-for
v-on
v-model  => v-bind + v-on

mvvm模式





 -->
  </body>
</html>
